package com.xyauto.theme.utils

import android.content.Context
import android.content.Intent
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import com.xyauto.theme.BuildConfig
import com.xyauto.theme.activity.DetailActivity
import com.xyauto.theme.activity.LocalActivity
import com.xyauto.theme.base.BaseFragment
import com.xyauto.theme.bean.IThemeBean

fun Context.getDrawableCompat(@DrawableRes resId: Int) = ContextCompat.getDrawable(this, resId)
fun Context.getColorCompat(@ColorRes resId: Int) = ContextCompat.getColor(this, resId)

fun Context.startDetails(themeBean: IThemeBean) = startActivity(
    Intent(this, DetailActivity::class.java).apply { putExtra(DetailActivity.DETAILS_KEY, themeBean) }
)

fun BaseFragment.startDetails(themeBean: IThemeBean) = context?.startDetails(themeBean)

fun Context.toHome() {
    val intent = Intent(Intent.ACTION_MAIN)
    intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
    intent.addCategory(Intent.CATEGORY_HOME)
    startActivity(intent)
}

fun Context.startLocalTheme() = startActivity(Intent(this, LocalActivity::class.java))



